package com.mango.demo.threadpool;

import com.mango.demo.threadcase3.Mycallable;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @Author：wlz
 * @Package：threadpool
 * @Project：mythread
 * @name：MythreadPooldemo
 * @Date：2023/3/28 20:41
 * @Filename：MythreadPooldemo
 */
public class MythreadPooldemo {
    public static void main(String[] args) {
        //获取线程池对象
        List<Callable<Integer>> list = new ArrayList<>();
        for (int i = 0; i < 2000; i++) {
            Mycallable mc = new Mycallable();
            list.add(mc);
        }

        ExecutorService pool = Executors.newFixedThreadPool(2000);
        ExecutorService pool1 = Executors.newCachedThreadPool();
        try {
            pool.invokeAll(list);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        try {
//            List<Future<Integer>> list1= pool1.invokeAll(list);
//            for (Future<Integer> i:list1
//                 ) {
//                System.out.println(i.get());
//            }
//        } catch (InterruptedException | ExecutionException e) {
//            e.printStackTrace();
//        }
        //关闭线程池
        pool.shutdown();
    }
}
